package com.easy.controller;

import com.easy.bean.Product;
import com.easy.service.ProductService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("product")
public class ProductController {
    @Autowired
    ProductService productService;

    @PostMapping
    public Result add(@RequestBody Product product){
        return Result.success("添加成功",productService.add(product));
    }
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        return Result.success("删除成功",productService.del(id));
    }
    @PutMapping
    public Result edit(@RequestBody Product product){
        return Result.success("编辑信息成功",productService.edit(product));
    }
    @GetMapping("list")
    public Result list(Product product){
        return Result.success(productService.all(product));
    }
    @GetMapping("{id}")
    public Result select(@PathVariable("id") Integer id){
        return Result.success(productService.one(id));
    }
    @GetMapping("page")
    public Result page(Page page, Product product){
        productService.page(page,product);
        return Result.success(page);
    }
}
